package src.dynamic_programming;

import java.util.Scanner;

/**
 * @author starsea
 * @date 2024-08-27 12:21
 */

public class Test08 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String t=in.nextLine();
        String s=in.nextLine();
        int m=s.length();
        int n=t.length();
        t=" "+t;
        s=" "+s;
        boolean[][] dp=new boolean[m+1][n+1];
        dp[0][0]=true;
        for(int j=1;j<=n;j++)
        {
            if(t.charAt(j)=='*')
            {
                dp[0][j]=true;
            }else
            {
                break;
            }
        }
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(s.charAt(i)==t.charAt(j) || t.charAt(j)=='?')
                {
                    dp[i][j]=dp[i-1][j-1];
                }else if(t.charAt(j)=='*')
                {
                   dp[i][j]=dp[i-1][j]|| dp[i][j-1];
                }
            }

        }
        System.out.println(dp[m][n]);
    }
    public static int longNum(String s,String p)
    {
        int m=s.length();
        int n=p.length();
        s=" "+s;
        p=" "+p;
        int max=0;
        int[][] dp=new int[m+1][n+1];
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(s.charAt(i)==p.charAt(j))
                {
                    dp[i][j]=dp[i-1][j-1]+1;
                }else
                {
                    dp[i][j]=0;
                }
                max=Math.max(dp[i][j],max);
            }

        }
        return max;
    }
}
